package com.wenwan.manage.pojo;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * 普通文章
 * 
 * @author Admin
 *
 */
@JsonInclude(Include.NON_NULL)
public class Article implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3640854435365204359L;

	/**
	 * 文章id
	 */
	private String id;
	/**
	 * 创建时间
	 */
	private String createTime;
	/**
	 * 创建时间的时间戳
	 */
	@SuppressWarnings("unused")
	private Long createTimestamp;
	/**
	 * 更新时间
	 */
	@SuppressWarnings("unused")
	private String updateTime;
	/**
	 * 文章标题
	 */
	private String title;
	/**
	 * 图文集合
	 */
	private List<Content> content = new ArrayList<Content>();
	/**
	 * json格式的图文集合
	 */
	@JsonIgnore
	private String contentJson;
	/**
	 * 此文章的发布者id
	 */
	private String userId;
	/**
	 * 此文章的发布者的信息
	 */
	private User user;
	/**
	 * 分享量
	 */
	private Integer countShare;
	/**
	 * 阅读量
	 */
	private Integer countReading;
	/**
	 * 点赞量
	 */
	private Integer countWell;
	/**
	 * 文章评论的数量，包括评论及子评论
	 */
	private Integer countComment;
	/**
	 * 当前用户是否已分享
	 */
	private Boolean isShare;
	/**
	 * 当前用户是否已阅读
	 */
	private Boolean isReading;
	/**
	 * 当前用户是否已点赞
	 */
	private Boolean isWell;
	/**
	 * 此文章是否通过审核了
	 */
	// @JsonIgnore
	private Boolean isExamine;
	/**
	 * 此文章是否已审核
	 */
	// @JsonIgnore
	private Boolean isAdopt;

	private Boolean isUndercarriage;

	@SuppressWarnings("unused")
	private Integer countImage;

	public Article() {
		// TODO Auto-generated constructor stub
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCreateTime() {
		try {
			return new SimpleDateFormat("yyyy-MM-dd")
					.format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(createTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return "0000-00-00";
		}
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getUpdateTime() {
		try {
			return new SimpleDateFormat("yyyy-MM-dd")
					.format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(createTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return "0000-00-00";
		}
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public List<Content> getContent() {
		if (contentJson != null) {
			content = new Gson().fromJson(contentJson, new TypeToken<List<Content>>() {
			}.getType());
		} else {
			content = null;
		}
		return content;
	}

	public void setContent(List<Content> content) {
		this.content = content;
	}

	public String getContentJson() {
		return contentJson;
	}

	public void setContentJson(String contentJson) {
		this.contentJson = contentJson;
	}

	public Boolean getIsShare() {
		return isShare;
	}

	public void setIsShare(Boolean isShare) {
		this.isShare = isShare;
	}

	public Boolean getIsReading() {
		return isReading;
	}

	public void setIsReading(Boolean isReading) {
		this.isReading = isReading;
	}

	public Boolean getIsWell() {
		return isWell;
	}

	public void setIsWell(Boolean isWell) {
		this.isWell = isWell;
	}

	public Integer getCountShare() {
		return countShare;
	}

	public void setCountShare(Integer countShare) {
		this.countShare = countShare;
	}

	public Integer getCountReading() {
		return countReading;
	}

	public void setCountReading(Integer countReading) {
		this.countReading = countReading;
	}

	public Integer getCountWell() {
		return countWell;
	}

	public void setCountWell(Integer countWell) {
		this.countWell = countWell;
	}

	public Boolean getIsExamine() {
		return isExamine;
	}

	public void setIsExamine(Boolean isExamine) {
		this.isExamine = isExamine;
	}

	public Boolean getIsAdopt() {
		return isAdopt;
	}

	public void setIsAdopt(Boolean isAdopt) {
		this.isAdopt = isAdopt;
	}

	public Long getCreateTimestamp() {
		try {
			return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(createTime).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return (long) 0;
		}
	}

	public void setCreateTimestamp(Long createTimestamp) {
		this.createTimestamp = createTimestamp;
	}

	public static void main(String[] args) {

	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Integer getCountComment() {
		return countComment;
	}

	public void setCountComment(Integer countComment) {
		this.countComment = countComment;
	}

	public Boolean getIsUndercarriage() {
		return isUndercarriage;
	}

	public void setIsUndercarriage(Boolean isUndercarriage) {
		this.isUndercarriage = isUndercarriage;
	}

	public Integer getCountImage() {
		List<Content> content = this.getContent();
		Integer countImage = 0;
		for (Content con : content) {
			if (con.getImage() != null) {
				countImage++;
			}
		}
		return countImage;
	}

	public void setCountImage(Integer countImage) {
		this.countImage = countImage;
	}

}
